package com.wanshi.utils;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Created by IntelliJ IDEA.
 * @Author Journey
 * @Date 2021/12/13 9:35
 */
public class DateFormatUtils {


    public  static String format(){
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);

        DecimalFormat df = new DecimalFormat("00");
        String month = df.format(calendar.get(Calendar.MONTH)+1);

        String day = df.format(calendar.get(Calendar.DAY_OF_MONTH));

        return year+month+day;
    }

    public static String formatDate(){
        //1.通过Util包中的Date获取
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        return dateFormat.format(date);
        //2.通过Util包的Calendar 获取
//        Calendar calendar= Calendar.getInstance();
//        SimpleDateFormat dateFormat1= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//        System.out.println(dateFormat1.format(calendar.getTime()));
//        return dateFormat1.format(calendar.getTime());


        //3.通过Util包的Calendar 获取时间，分别获取年月日时分秒
//        Calendar cal=Calendar.getInstance();
//        int y=cal.get(Calendar.YEAR);
//        int m=cal.get(Calendar.MONTH);//当前月份的前一个月
//        int d=cal.get(Calendar.DATE);
//        int h=cal.get(Calendar.HOUR_OF_DAY);
//        int mi=cal.get(Calendar.MINUTE);
//        int s=cal.get(Calendar.SECOND);
//       return String.valueOf(y+m+d+h+mi+s);
    }

}
